﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Projects_PercentageCalculator : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {

  }

  //Validate input

  public bool isInputValid(string a)
  {
    double aNum;

    bool isANum = double.TryParse(a, out aNum);

    if (isANum)
    {
      return true;
    }
    else
    {
      return false;
    }
  }

  
  //Functions for calculations

  public double calculation1(double a, double b)
  {
    double result = (a / 100) * b;

    return result;
  }

  public double calculation2(double a, double b)
  {
    double result = (a * 100) / b;

    return result;
  }

  public double calculation3(double a, double b)
  {
    double result = a / (b / 100);

    return result;
  }

  //Calculate button clicks

  protected void BtnCalculateQ1_Click(object sender, EventArgs e)
  {
    if (isInputValid(Q1Input1.Text) && isInputValid(Q1Input2.Text))
    {
      LblAnswerQ1.Text = calculation1(Convert.ToDouble(Q1Input1.Text), Convert.ToDouble(Q1Input2.Text)).ToString();
    }
    else
    {
      LblAnswerQ1.Text = "Invalid Input";
    }
  }

  protected void BtnCalculateQ2_Click(object sender, EventArgs e)
  {
    if (isInputValid(Q2Input1.Text) && isInputValid(Q2Input2.Text))
    {
      LblAnswerQ2.Text = calculation1(Convert.ToDouble(Q2Input1.Text), Convert.ToDouble(Q2Input2.Text)).ToString();
    }
    else
    {
      LblAnswerQ2.Text = "Invalid Input";
    }
  }

  protected void BtnCalculateQ3_Click(object sender, EventArgs e)
  {
    if (isInputValid(Q3Input1.Text) && isInputValid(Q3Input2.Text))
    {
      LblAnswerQ3.Text = calculation1(Convert.ToDouble(Q3Input1.Text), Convert.ToDouble(Q3Input2.Text)).ToString();
    }
    else
    {
      LblAnswerQ3.Text = "Invalid Input";
    }
  }

  // Show / Hide Solution Buttons

  protected void BtnShowSolution_Click(object sender, EventArgs e)
  {
    ObjectivePanel.Visible = false;
    SolutionPanel.Visible = true;
  }

  protected void BtnShowObjective_Click(object sender, EventArgs e)
  {
    ObjectivePanel.Visible = true;
    SolutionPanel.Visible = false;
  }

}